package br.unesp.ibb.lbbc.testes;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.OptimizationException;
import org.apache.commons.math.optimization.RealPointValuePair;
import org.apache.commons.math.optimization.linear.LinearConstraint;
import org.apache.commons.math.optimization.linear.LinearObjectiveFunction;
import org.apache.commons.math.optimization.linear.Relationship;
import org.apache.commons.math.optimization.linear.SimplexSolver;

public class TestaLP {

	public TestaLP(){
		LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { -2, 1 }, -5);
		Collection constraints = new ArrayList();
		constraints.add(new LinearConstraint(new double[] { 1, 2 }, Relationship.LEQ, 6));
		constraints.add(new LinearConstraint(new double[] { 3, 2 }, Relationship.LEQ, 12));
		constraints.add(new LinearConstraint(new double[] { 0, 1 }, Relationship.GEQ, 0));
		
		// create and run the solver
		RealPointValuePair solution = null;
		try {
			solution = new SimplexSolver().optimize(f, constraints, GoalType.MINIMIZE, false);
		} catch (OptimizationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// get the solution
		
		
		double x = solution.getPoint()[0];
		double y = solution.getPoint()[1];
		double min = solution.getValue();
		
		
		System.out.println(x);
		System.out.println(y);
		System.out.println(min+"\n");
		
		
	}
	
	
	
	public static void main(String[] args) {
		TestaLP t = new TestaLP();}

}
